﻿// ....................................................................................................................
//	Author: Copyright (C) 2012 Ing. Marek Hubal
//	Email: hubal@acasoftware.org
// ....................................................................................................................

using System;

namespace core
{
    /// <summary>Trieda IListBox</summary>
	public class IListBox : System.Windows.Forms.ListBox
	{
	}

    /// <summary>Trieda ICheckedListBox</summary>
    public class ICheckedListBox : System.Windows.Forms.CheckedListBox
    {
        protected System.Collections.Generic.List<string> FStringIDs; // Zoznam ID

        /// <summary>Property: SelectedItemID</summary>
        public string SelectedItemID
        {
            get
            {
                return SelectedIndex == -1 ? "" : FStringIDs[SelectedIndex];
            }
            set
            {
                SelectedIndex = FStringIDs.IndexOf(value);
            }
        }
        /// <summary>Property: AllCheckedItemIDs</summary>
        public string AllCheckedItemIDs
        {
            get
            {
                System.Text.StringBuilder B = new System.Text.StringBuilder(); // Builder pre vysledok
                for (int i = 0; i < CheckedIndices.Count; i++)
                {
                    B.Append(FStringIDs[CheckedIndices[i]]);
                    B.Append(';');
                }
                if (B.Length > 0) B.Length--; // Odstranim posledny oddelovac
                return B.ToString();
            }
        }

        /// <summary>Konstruktor</summary>
        public ICheckedListBox()
        {
            FStringIDs = new System.Collections.Generic.List<string>();
        }

        /// <summary>Zaradenie zaznamu aj s ID</summary>
        /// <param name="pText">text</param>
        /// <param name="pID">ID</param>
        public void AddItem(string pText, string pID)
        {
            Items.Add(pText);
            FStringIDs.Add(pID);
        }
    }
}
